package org.behrang.macbeans;

import apple.laf.CUIAquaLookAndFeel;
import javax.swing.UIManager;
import org.netbeans.swing.plaf.Startup;
import org.openide.ErrorManager;
import org.openide.modules.ModuleInstall;

/**
 * Manages a module's lifecycle. Remember that an installer is optional and
 * often not needed at all.
 */
public class Installer extends ModuleInstall {

    public static String LNF_CLASS_NAME = "apple.laf.CUIAquaLookAndFeel";
    
    @Override
    public void restored() {
        try {            
            UIManager.setLookAndFeel(LNF_CLASS_NAME);
            Startup.run(CUIAquaLookAndFeel.class, 0, null);
            MacBeansLFCustoms customs = new MacBeansLFCustoms();
            UIManager.getDefaults().putDefaults(customs.createApplicationSpecificKeysAndValues());
            UIManager.getDefaults().putDefaults(customs.createGuaranteedKeysAndValues());
            UIManager.getDefaults().putDefaults(customs.createLookAndFeelCustomizationKeysAndValues());
        } catch (Exception e) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                ErrorManager.getDefault().notify(e);
                throw new RuntimeException(e);
            }            
        }
    }
}
